<template>
  <div class="app-container">
    <!-- 页眉 -->
    <div class="header">
      <div class="header-content">
        <img src="@/assets/imgs/logo.jpg" alt="" class="logo">
        <div class="title">大连民族大学实验室成果管理系统</div>
      </div>
    </div>

    <!-- 主体内容 -->
    <div class="main-container">
      <!-- 左侧侧边栏 -->
      <div class="sidebar">
        <el-menu router class="menu" :default-active="$route.path" :default-openeds="['/home', '2', '3']">
          <!-- 系统首页 -->
          <el-menu-item index="/home">
            <el-icon class="menu-icon"></el-icon>
            <span>系统首页</span>
          </el-menu-item>

          <!-- 科研成果管理 -->
          <el-sub-menu index="2">
            <template #title>
              <el-icon class="menu-icon"></el-icon>
              <span>科研成果管理</span>
            </template>
            <el-menu-item index="/scientificList" v-if="user.role === 'STUDENT'">
              <el-icon class="menu-icon"></el-icon>
              <span>本人科研成果管理</span>
            </el-menu-item>
            <el-menu-item index="/TeacherS" v-if="user.role === 'ADMIN'">
              <el-icon class="menu-icon"></el-icon>
              <span>科研成果管理</span>
            </el-menu-item>
            <el-menu-item index="/Zx" v-if="user.role === 'ADMIN'">
              <el-icon class="menu-icon"></el-icon>
              <span>纵向课题管理</span>
            </el-menu-item>
            <el-menu-item index="/Hx" v-if="user.role === 'ADMIN'">
              <el-icon class="menu-icon"></el-icon>
              <span>横向课题管理</span>
            </el-menu-item>
            <el-menu-item index="/eassy" v-if="user.role === 'ADMIN'">
              <el-icon class="menu-icon"></el-icon>
              <span>论文管理</span>
            </el-menu-item>
          </el-sub-menu>

          <!-- 用户管理 -->
          <el-sub-menu index="4" v-if="user.role === 'ADMIN'">
            <template #title>
              <el-icon class="menu-icon"></el-icon>
              <span>用户管理</span>
            </template>
            <el-menu-item index="/student">
              <el-icon class="menu-icon"></el-icon>
              <span>学生信息</span>
            </el-menu-item>
          </el-sub-menu>

          <!-- 学生基本信息管理 -->
          <el-menu-item index="/person" v-if="user.role === 'STUDENT'">
            <el-icon class="menu-icon"></el-icon>
            <span>学生基本信息管理</span>
          </el-menu-item>

          <!-- 退出系统 -->
          <el-menu-item index="login" @click="logout">
            <el-icon class="menu-icon"></el-icon>
            <span>退出系统</span>
          </el-menu-item>
        </el-menu>
      </div>

      <!-- 右侧内容 -->
      <div class="content">
        <router-view />
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRoute } from 'vue-router'

const $route = useRoute()
const user = JSON.parse(localStorage.getItem('student-user') || '{}')

const logout = () => {
  localStorage.removeItem('student-user')
}
</script>

<style scoped>
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.header {
  height: 60px;
  background-color: #24527a;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
}
.el-menu-item.is-active[data-v-24cd5276] {
    background-color: #24527a !important;
}
.header-content {
  padding-left: 20px;
  display: flex;
  align-items: center;
}

.logo {
  width: 40px;
}

.title {
  font-weight: bold;
  font-size: 24px;
  margin-left: 5px;
  color: #fff;
}

.main-container {
  display: flex;
  flex: 1;
}

.sidebar {
  width: 200px;
  background-color: #f0f2f5;
  border-right: 1px solid #ddd;
  min-height: calc(100vh - 60px);
  padding-top: 10px;
}

.menu {
  border: none;
}

.menu-icon {
  margin-right: 10px;
}

.content {
  flex: 1;
  background-color: #fff;
  padding: 10px;
}

.el-menu-item.is-active {
  background-color: #dcede9 !important;
}

.el-menu-item:hover {
  color: #11a983;
}

:deep(th) {
  color: #333;
}
</style>

